package ca.uwo.android;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class BaseListMenuActivity extends ListActivity implements BaseMenuActivityInterface{
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		// Handle item selection
		switch (item.getItemId()) {
		case R.id.menu_info_item: {

			Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.info_url)));
			startActivity(browser);
			return true;
		}
		case R.id.menu_help_item: {
			showWebPage(getString(R.string.help_url));
			return true;
		}
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	public void showWebPage(String url) {
		Intent openHelpPage = new Intent(BaseListMenuActivity.this,
				ca.uwo.android.ViewWebPage.class);
		openHelpPage.putExtra("URL", url);
		startActivity(openHelpPage);
	}

}
